﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;

namespace Gencode.Web.Errorhandling
{
	public class Handler : Gencode.Common.Errorhandling.Handler,Gencode.Common.Errorhandling.IHandler
	{
		/// <summary>
		/// Shows error message on the page defined in asppage
		/// </summary>
		/// <param name="message">Message to be displayed</param>
		/// <param name="title">Error title</param>
		/// <param name="asppage">Name of page that contains messagehandler</param>
		public static void ShowError(string message, string title, string asppage)
		{
			HttpContext.Current.Session["MESSAGE"] = message;
            HttpContext.Current.Session["TITLE"] = title;
			HttpContext.Current.Response.Redirect(asppage);
		}

        /// <summary>
        /// Shows error message on the page defined in asppage
        /// </summary>
        /// <param name="message">Message to be displayed</param>
        /// <param name="asppage">Name of page that contains messagehandler</param>
        public static void ShowError(string message, string asppage)
        {
            HttpContext.Current.Session["MESSAGE"] = message;
            HttpContext.Current.Session["TITLE"] = "Error";
            HttpContext.Current.Response.Redirect(asppage);
        }

		/// <summary>
		/// Shows error message on the page "NoticePanel.aspx"
		/// </summary>
		/// <param name="message">Message to be displayed</param>
		/// <param name="defaultPage">NoticePanel.aspx</param>
		public static void ShowError(string message, bool defaultPage)
		{
			ShowError(message, "NoticePanel.aspx");
		}

		#region IHandler Members

		public void ShowError(string errorMessage)
		{
			Page page = new Page();
			ShowError(errorMessage, true);
		}

		#endregion
	}
}
